import os

baseDir = "F:\darkmap_tiles"


def is_html(file):
    with open(file, 'rb') as opf:
        if opf.readable():
            line = opf.read(5)
            try:
                line = line.decode('utf-8')
                if line.startswith('<html'):
                    return True
                else:
                    return False
            except UnicodeDecodeError:
                return False


def list_all_file(base_path):
    files = os.listdir(base_path)
    for i in range(len(files)):
        path = os.path.join(base_path, files[i])
        if os.path.isfile(path):
            if is_html(path):
                os.remove(path)
                print("删除文件:", path)
        elif os.path.isdir(path):
            # pass
            print(path)
            list_all_file(path)


if __name__ == '__main__':
    list_all_file(baseDir)
